package triannon.client.map;

import org.jdom.Element;

import triannon.client.sprites.Field;
import triannon.client.sprites.ISprite;
import triannon.client.util.TMath;

public class Map implements IMap {
	private final Field field;
	private final int mapWidth;
	private final int mapHeight;

	private final int viewWidth;
	private final int viewHeight;

	public Map(int mapSizeWidth, int mapSizeHeight) {
		this.field = new Field(mapSizeWidth, mapSizeHeight);
		this.mapWidth = mapSizeWidth;
		this.mapHeight = mapSizeHeight;
		this.viewWidth = TMath.toWorldCoorninates(mapSizeWidth);
		this.viewHeight = TMath.toWorldCoorninates(mapSizeHeight);
	}

	@Override
	public Field getField() {
		return field;
	}

	@Override
	public int getMapWidth() {
		return mapWidth;
	}

	@Override
	public int getMapHeight() {
		return mapHeight;
	}

	@Override
	public int getHeight() {
		return viewHeight;
	}

	@Override
	public int getWidth() {
		return viewWidth;
	}

	@Override
	public void parseXML(Element element) {

	}

	@Override
	public Element toXML() {
		Element element = new Element("map");
		element.setAttribute("width", String.valueOf(mapWidth));
		element.setAttribute("height", String.valueOf(mapHeight));

		for (ISprite sprite : field) {
			element.addContent(sprite.toXML());
		}

		return element;
	}

}
